package com.huatai.bi.controller.bigScreen;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huatai.bi.dto.BigScreenPageDTO;
import com.huatai.bi.dto.bigScreen.*;
import com.huatai.bi.entity.BigScreenPageEntity;
import com.huatai.bi.query.ScreenQuery;
import com.huatai.bi.service.BigScreenPageService;
import com.huatai.bi.vo.bigScreenVO.BigScreenDownList;
import com.huatai.bi.vo.bigScreenVO.BigScreenPageVersionVO;
import com.huatai.bi.vo.bigScreenVO.DownTreeListVO;
import com.huatai.bi.vo.bigScreenVO.ScreenVersionVO;
import com.huatai.common.api.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.huatai.bi.controller.bigScreen
 * @Author: hecaiy
 * @CreateTime: 2024-06-21  10:45
 * @Description: TODO 态势管理
 * @Version: 1.0
 */
@RestController
@RequestMapping("/screenManage")
@Api(value = "大屏态势管理(大屏)",tags = "大屏态势管理(大屏)")
public class BigScreenManageController {

    @Autowired
    private BigScreenPageService bigScreenPageService;

    @PostMapping("/updateScreenConfig")
    @ApiOperation(value = "修改大屏基础配置")
    public R<Boolean> updateScreenConfig(@RequestBody BigScreenPageEntity dto){
        return R.data(bigScreenPageService.updateScreenConfig(dto));
    }

    @PostMapping("/getScreenByParentCode")
    @ApiOperation(value = "根据编码获取态势")
    public R<BigScreenPageVersionVO> getScreenByParentCode(@RequestBody SaveAsVersionScreenDTO dto){
        return R.data(bigScreenPageService.getScreenByParentCode(dto));
    }

    @PostMapping("/getScreenByCode")
    @ApiOperation(value = "根据code切换历史版本")
    public R<BigScreenPageVersionVO> getScreenByCode(@RequestBody SaveAsVersionScreenDTO dto){
        return R.data(bigScreenPageService.getScreenByCode(dto.getCode()));
    }

	@PostMapping("/copyScreen")
	@ApiOperation(value = "复制态势")
	public R<List<BigScreenPageEntity>> copyScreen(@RequestBody BigScreenPageDTO dto){
		return R.data(bigScreenPageService.copyScreen(dto),"操作成功");
	}

    @PostMapping("/addScreen")
    @ApiOperation(value = "新增态势")
    public R<String> addScreen(@RequestBody BigScreenPageDTO dto){
        return R.data(bigScreenPageService.addScreen(dto),"操作成功");
    }

    @PostMapping("/updateScreen")
    @ApiOperation(value = "修改态势")
    public R<String> updateScreen(@RequestBody BigScreenPageDTO dto){
        return R.data(bigScreenPageService.updateScreen(dto));
    }

    @PostMapping("/removeLimit")
    @ApiOperation(value = "移除限制")
    public R<Boolean> removeLimit(@RequestBody HistoryScreenDTO dto){
        return R.data(bigScreenPageService.removeLimit(dto.getCode()));
    }

    @PostMapping("/saveAsScreen")
    @ApiOperation(value = "另存为态势")
    public R<Boolean> saveAsScreen(@RequestBody SaveAsScreenDTO dto){
        return R.data(bigScreenPageService.saveAsScreen(dto.getParentCode(),dto.getScreenParentCode(),dto.getName()));
    }

    @PostMapping("/saveAsVersion")
    @ApiOperation(value = "另存为版本")
    public R<Boolean> saveAsVersion(@RequestBody SaveAsVersionScreenDTO dto){
        return R.data(bigScreenPageService.saveAsVersion(dto.getCode(),dto.getName()));
    }

	@PostMapping("/updateVersionName")
	@ApiOperation(value = "修改版本名称")
	public R<Boolean> updateVersionName(@RequestBody SaveAsVersionScreenDTO dto){
		return R.data(bigScreenPageService.updateVersionName(dto.getCode(),dto.getName()));
	}

    @PostMapping("/getHistoryVerison")
    @ApiOperation(value = "获取历史版本")
    public R<List<ScreenVersionVO>> getHistoryVerison(@RequestBody HistoryScreenDTO dto){
        return R.data(bigScreenPageService.getHistoryVerison(dto.getParentCode(),dto.getCode()));
    }

    @PostMapping("/getPage")
    @ApiOperation(value = "分页查询态势")
    public R<Page<BigScreenPageEntity>> getPage(@RequestBody ScreenQuery query){
        return R.data(bigScreenPageService.getPage(query));
    }

    @PostMapping("/removeByCode")
    @ApiOperation(value = "移除态势")
    public R<Boolean> removeByCode(@RequestBody ScreenManageRemoveDTO dto){
        return R.data(bigScreenPageService.removeByCode(dto.getCode()));
    }

    @PostMapping("/authScreenBycode")
    @ApiOperation(value = "授权态势")
    public R<Boolean> authScreenBycode(@RequestBody ScreenManageAuthDTO dto){
        return R.data(bigScreenPageService.authScreenBycode(dto.getCode(),dto.getSeatIds()));
    }

    @PostMapping("/publishScreen")
    @ApiOperation(value = "发布态势")
    public R<Boolean> publishScreen(@RequestBody ScreenPublishDTO dto){
        return R.data(bigScreenPageService.publishScreen(dto.getCode(),dto.getPublishDir(),dto.getPublishOrder()));
    }

	@GetMapping("/cancelpublishScreen/{code}")
	@ApiOperation(value = "取消发布态势")
	public R<Boolean> cancelPublishScreen(@PathVariable("code") String code){
		return R.data(bigScreenPageService.cancelPublishScreen(code));
	}

    @GetMapping("/getDownList/{screenParentCode}")
    @ApiOperation(value = "获取下钻目录")
    public R<List<BigScreenDownList>> getDownList(@PathVariable("screenParentCode")String screenParentCode){
        return R.data(bigScreenPageService.getDownList(screenParentCode));
    }

    @PostMapping("/getDownListTree")
    @ApiOperation(value = "获取下钻目录树")
    public R<List<DownTreeListVO>> getDownListTree(@RequestBody ScreenRefreshConfigDTO screenParentCode){
        return R.data(bigScreenPageService.getDownListTree(screenParentCode.getCode()));
    }

    @PostMapping("/auth")
    @ApiOperation(value = "授权")
    public R auth(@RequestBody ScreenAuthDTO auth){
        bigScreenPageService.auth(auth);
        return R.data(null);
    }

    @GetMapping("/auth/{code}")
    @ApiOperation(value = "获取授权")
    public R<List<Long>> getAuth(@PathVariable("code") String code){
        return R.data(bigScreenPageService.getAuth(code));
    }
}
